package com.shop.zzh.controller;

import com.shop.zzh.entity.ZcVideo;
import com.shop.zzh.mbg.mapper.VideoMapper;
import com.shop.zzh.result.ContentResultForm;
import com.shop.zzh.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @program: zzh
 * @description: 视频
 * @author: zhuzh
 * @create: 2019-12-11 11:01
 **/
@Api(value = "视频数据控制类")
@RestController
@RequestMapping("/video")
public class VideoController {
	private static final Logger logger = LoggerFactory.getLogger(VideoController.class);

	@Autowired
	private VideoService videoService;
	@Autowired
	private VideoMapper videoMapper;

	@ApiOperation(value = "获取视频数据集",notes = "获取视频数据集")
	@PostMapping(value="/list")
	public ContentResultForm getVideoListData(int pageNum, int pageSize, String keyword)throws  Exception{
		ZcVideo video = new ZcVideo();
		video.setKeyword(keyword);
		try {
			return new ContentResultForm(true,videoService.getVideoListData(pageNum,pageSize,video));
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return new ContentResultForm(false, "首页-->获取视频列表数据异常");
		}
	}

	@ApiOperation(value = "打开播放视频页面",notes = "打开播放视频页面")
	@GetMapping(value="/openVideo/{id}")
	public ModelAndView openVideo(@PathVariable("id")String id)throws  Exception{
		//根据id查看视频信息，视频地址
		if(StringUtils.isBlank(id)){
			logger.error("查询不到视频信息");
			return null;
		}
		ZcVideo zcVideo = videoMapper.selectOneVideoListById(id);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("videoInfo",zcVideo);
		modelAndView.setViewName("back/openVideo");
		return modelAndView;
	}
}
